<?php
require_once APPLICATION_PATH . "/models/ModelBase.php";

class Admins extends TT_Table_Abstract
{
    protected $_name = 'users';
    protected $_primary = 'uid';
    
    // Them quyen quan tri
    public function addmoderator($user)
    {
        $db = $this->getSessionDB();
        $sql = "UPDATE users SET level = '1' WHERE name = ?";
        return $db->query($sql,array($user));
    }
    
    // Bo quyen quan tri
    public function removemoderator($user)
    {
        $db = $this->getSessionDB();
        $sql = "UPDATE users SET level = '0' WHERE name = ?";
        return $db->query($sql,array($user));
    }
    
    // Xoa nguoi dung
    public function removeuser($user)
    {
        $db=  $this->getSessionDB();
        $sql = "DELETE FROM users WHERE name = ?";
        return $db->query($sql,array($user));
    }
    
    // Liet ke ng dung
    /*public function members()
    {
        $db = $this->getSessionDB();
        $sql = "SELECT name FROM users WHERE level = '0' AND admin = '0'";
        $array = array();
        $a = $db->fetchAll($sql);
        return $a;
    }
    */
    public function members($page,$page_rows)     // Liet ke user
    {
        $page = (int)$page;
        $page_rows = (int)$page_rows;
        $db = $this->getSessionDB();
        $sql = "SELECT name FROM users WHERE level = '0' AND admin = '0' LIMIT $page,$page_rows";
        $array = array();
        $a = $db->fetchAll($sql);
        return $a;
    }
    
    public function members_num()     // Liet ke user
    {
        $page = (int)$page;
        $page_rows = (int)$page_rows;
        $db = $this->getSessionDB();
        $sql = "SELECT count(name) as num FROM users WHERE level = '0' AND admin = '0'";
        $array = array();
        $a = $db->fetchAll($sql);
        return $a;
    }
    
    // Hien thi ten user
    public function checkInfo($username)
    {
        $db = $this->getSessionDB();
        $sql = "SELECT * FROM users where name = ?";
        return $db->fetchRow($sql, array($username));   
    }
    
    // Liet ke quan tri vien
    public function moderator()
    {
        $db = $this->getSessionDB();
        $sql = "SELECT name FROM users WHERE level = '1'";
        $array = array();
        $a = $db->fetchAll($sql);
        return $a;
    }
}
?>
